{% extends 'rebs/layouts/base.html' %}

{% block title %}Rebs - Project{% endblock %}

{% block content %}
    {% load humanize widget_tweaks %}

    <!-- Start Content-->
    <div class="container-fluid">

        <!-- start page title -->
        {% include 'rebs/partials/content_title.html' with  second_bs="신규 프로젝트" title="세부 정보 관리" %}
        <!-- end page title -->

        <div class="row">
            <form class="form-horizontal p-0 col-12" method="get">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">

                            {% with menu_order='2' %}
                                {% include 'rebs_project/partials/head_menu.html' %}
                            {% endwith %}

                            <div class="row">
                                {% include 'rebs/partials/project_select.html' %}
                                <div class="col-sm-12 col-md-6"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

            <form method="post" class="col-12 p-0 needs-validation" novalidate>
                {% csrf_token %}
                {{ formset.management_form }}
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body pb-1">
                            <div class="row">

                                <div class="col mb-3">
                                    <!-- Button Group -->
                                    <div class="btn-group mb-2">
                                        <button type="button" class="btn btn-primary">차수 분류 등록</button>
                                        <button type="button" class="btn btn-light"
                                                onclick="location.href='{% url 'rebs:project:set-unit-type' %}'">타입 정보 등록</button>
                                        <button type="button" class="btn btn-light"
                                                onclick="location.href='{% url 'rebs:project:set-floor-type' %}'">층별 조건 등록</button>
                                        <button type="button" class="btn btn-light"
                                                onclick="location.href='{% url 'rebs:project:set-sales-price' %}'">분양 가격 등록</button>
                                        <button type="button" class="btn btn-light"
                                                onclick="location.href='{% url 'rebs:project:set-payment-order' %}'">납부 회차 등록</button>
                                        <button type="button" class="btn btn-light"
                                                onclick="location.href='{% url 'rebs:project:set-payment-amount' %}'">납부 금액 등록</button>
                                    </div>
                                </div>

                                <div class="col-12 table-responsive">
                                    <table id="scroll-horizontal-datatable"
                                           class="table table-hover table-centered table-condensed table-sm w-100 m-0 nowrap">
                                        <thead>
                                        <tr class="bg-nav-pills">
                                            <th class="text-center">등록차수</th>
                                            <th class="text-center">구 분</th>
                                            <th class="text-center">차수명</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        {% for form in formset %}
                                            {% for hidden in form.hidden_fields %}
                                                {{ hidden }}
                                            {% endfor %}
                                            <tr>
                                                <td class="text-center">
                                                    {{ form.order_number|add_class:"form-control text-right"|attr:"placeholder:등록차수" }}
                                                    <span class="text-danger">{{ form.order_number.errors }}</span>
                                                </td>
                                                <td class="text-center">
                                                    {{ form.sort|add_class:"form-control select2"|attr:"data-toggle:select2" }}
                                                    <span class="text-danger">{{ form.sort.errors }}</span>
                                                </td>
                                                <td class="text-center">
                                                    {{ form.order_group_name|add_class:"form-control"|attr:"placeholder:차수명" }}
                                                    <span class="text-danger">{{ form.order_group_name.errors }}</span>
                                                </td>
                                            </tr>
                                        {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            {% if is_paginated %}

                                {# to_first_last :: 맨처음 / 맨끝으로 버튼 사용 여부 #}
                                {# page_class ex:: pagination-rounded pagination-sm pagination-lg justify-content-center justify-content-end #}
                                {% include 'partials/pagination.html' with to_first_last="ok" page_class="pagination-rounded justify-content-end" %}

                            {% endif %}
                        </div>
                    </div>
                </div>

                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="form-group mb-0 justify-content-end row">
                                    <div class="col-12">
                                        {% if request.user.is_superuser or request.user.staffauth.project > '1' %}
                                            <button type="submit" class="btn btn-primary">등록하기</button>
                                        {% else %}
                                            <button type="button" class="btn btn-outline-secondary"
                                                    onclick="alert('세부 정보 관리 권한이 없습니다. 관리자에게 문의하여 주십시요.')">조회권한 사용자
                                            </button>
                                        {% endif %}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div> <!-- container -->

{% endblock %}

{% block third_party_js %}
    <script>
      window.onload = function () {
        document.getElementById('id_project_sel').setAttribute('onchange', 'submit()')
      }
    </script>
{% endblock %}
